<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5shiv.js"></script>
    <script type="text/javascript" src="../js/respond.min.js"></script>
    <![endif]-->
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="../css/H-ui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../css/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <title></title>
</head>
<body>
<article class="page-container saveProductChannelFee">
    <form action="" method="post" class="form form-horizontal" id="tradeForm">
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>产品Id</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="productId" name="productId"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>产品名称</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="productName" name="productName"
                           onblur="replaceSpace(this.value,this.id)" disabled>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>客户VIP类型：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="custVipType" id="custVipType" disabled="disabled">
                        <option value="">-请选择-</option>
                        <option value="0">游客</option>
                        <option value="10">VIP</option>
                        <option value="20">配送商</option>
                    </select>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red"></span>产品分类：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="category" id="category" disabled="disabled">
                        <option value="">-请选择-</option>
                        <option value="11">白酒</option>
                        <option value="12">啤酒</option>
                        <option value="13">葡萄酒</option>
                        <option value="14">黄酒</option>
                        <option value="21">注册VIP</option>
                        <option value="22">注册配送商</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>业务种类：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="businessType" id="businessType">
                        <option value="">-请选择-</option>
                        <option value="10">游客购买</option>
                        <option value="11">vip复购</option>
                        <option value="12">配送商复购</option>
                        <option value="21">注册VIP</option>
                        <option value="22">注册配送商</option>
                    </select>
                </div>
            </div>
            <div class="row cl  col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>渠道代数：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="commissionGeneration" id="commissionGeneration">
                        <option value="">-请选择-</option>
                        <option value="1">一代</option>
                        <option value="2">二代</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>推广佣金费用：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="fee" name="fee"
                           onblur="replaceSpace(this.value,this.id)">
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-8">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-9">
                    <div class="btn btn-success radius" onclick="submit()">修改</div>
                </div>
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/js/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/js/H-ui.js"></script>
<script type="text/javascript" src="/js/H-ui.min.js"></script>
<script type="text/javascript" src="/js/postJson.js"></script>
<script type="text/javascript" src="/js/root.js"></script>
<script>
    var channelFeeId = parent.$("#dataId").attr("channelFeeId");
    var pageNum = parent.$("#dataId").attr("pageNum");
    // console.log("---"+channelFeeId+"--------")
    function getData() {
        var url = "/productController/getProductChannelFeeById";
        $.ajax({
            url: url,
            data: {
                "id": channelFeeId
            },
            type: "post",
            async: false,
            dataType: 'json',
            success: function (msg) {
                // console.log(JSON.stringify(msg))
                if (msg.success == true) {
                    $("#businessType").find("option[value='" + msg.data.businessType + "']").attr("selected", true);
                    $("#commissionGeneration").find("option[value='" + msg.data.commissionGeneration + "']").attr("selected", true);
                    $("#category").find("option[value='" + msg.data.category + "']").attr("selected", true);
                    $("#custVipType").find("option[value='" + msg.data.custVipType + "']").attr("selected", true);
                    $("#fee").val(msg.data.fee)
                    $("#productId").val(msg.data.productId)
                    $("#productName").val(msg.data.productName)
                }
            }
        })
    }
    getData()
    /*提交*/
    var flag = true;
    function submit() {
        if (!flag) {
            return false;
        }
        flag = false;
        var businessType = $("#businessType").find("option:selected").val();
        var productId = $("#productId").val();
        var commissionGeneration = $("#commissionGeneration").find("option:selected").val();
        var fee = $("#fee").val();

        if(businessType == null || businessType == '') {
            parent.layer.msg('业务种类不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        // if(productId == null) {
        //     parent.layer.msg('产品Id不能为空', {icon: 2, time: 3000});
        //     flag = true;
        //     return false;
        // }
        if(commissionGeneration == null || commissionGeneration == '') {
            parent.layer.msg('渠道代数不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(status == null) {
            parent.layer.msg('营销规则状态不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(fee == '' || fee == null) {
            parent.layer.msg('推广佣金费用不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        var jsonArry = {
            "productId": productId,
            "commissionGeneration": commissionGeneration,
            "businessType": businessType,
            "fee": fee,
            "id": channelFeeId
        }
        var jsondata = JSON.stringify(jsonArry);
        // console.log(jsondata)
        var url = "/productController/updateProductChannelFee";
        $.ajax({
            type: "post",
            url: url,
            data: jsondata,
            dataType: "json",
            contentType: "application/json",
            async: false,
            success: function (msg) {
                if (msg.success == true) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.msg("修改成功！", {icon: 1, time: 3000});
                    window.parent.frames.getData(Number(pageNum));
                    parent.layer.close(index);
                } else {
                    parent.layer.msg(msg.errorMessage, {icon: 2, time: 5000});
                    flag = true;
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var XmlStatus = XMLHttpRequest.status
                if (XmlStatus == 401) {
                    alert(XmlError.error401)
                    parent.window.location.href = "login"
                }
                if (XmlStatus == 403) {
                    alert(XmlError.error403)
                }
            }
        })
    }
</script>
</body>
</html>